package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.DeliveryInfoService;
import service.TaskInfoService;

@WebServlet("/DeliveryOperationServlet")
public class DeliveryOperationServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public DeliveryOperationServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		TaskInfoService service = new TaskInfoService();
		String operation = request.getParameter("operation");
		String addressee = request.getParameter("addressee");
		String tel = request.getParameter("tel");
		String address = request.getParameter("address");
		String[] tasknos = request.getParameterValues("tasknos");
		String deliveryno = request.getParameter("deliveryno");
		String payNo = request.getParameter("payNo");
		String freight = request.getParameter("freight");
		switch(operation) {
		case "delivery" :
			service.deliveryTask(tasknos, address, addressee, tel);
			break;
		case "deliveried" :
			service.deliveried(tasknos, deliveryno, payNo, freight);
			break;
		case "isPay":
			String[] deliverynos = request.getParameterValues("deliverynos");
			for (String string : deliverynos) {
				new DeliveryInfoService().getMapper().isPay(string);
			}
			break;
		case "export":
			
			break;
		}
	}

}
